package com.javalong.affairs.module.renwujinzhang.activity.praise;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.adapter.BaseAdapter;
import com.javalong.affairs.base.common.ViewHolder;
import com.javalong.affairs.base.model.Praise;
import com.javalong.affairs.base.model.Suggest;
import com.javalong.affairs.base.utils.TimeUtils;

import java.util.List;

/**
 * Created by 杨观回 on 2016/2/28 0028.
 */
public class PraiseAdapter extends BaseAdapter {

    public PraiseAdapter(Context context, List<?> dataList) {
        super(context, dataList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (position == 0) {
            View view = createFirstItem(convertView, parent);
            return view;
        }
        Praise suggest = (Praise) dataList.get(position - 1);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_suggestlist, parent, false);
            ViewHolder holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        TextView tv_time = holder.getView(R.id.tv_time);
        TextView tv_username = holder.getView(R.id.tv_username);
        TextView tv_content = holder.getView(R.id.tv_content);
        tv_time.setText(TimeUtils.getFormat4Time(suggest.getTimeCreate()));
        tv_username.setText(suggest.getUserName());
        tv_content.setText(suggest.getContent());
        return convertView;
    }

    private View createFirstItem(View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_suggestlist, parent, false);
            ViewHolder holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        TextView tv_time = holder.getView(R.id.tv_time);
        TextView tv_username = holder.getView(R.id.tv_username);
        TextView tv_content = holder.getView(R.id.tv_content);
        tv_time.setText("时间");
        tv_username.setText("姓名");
        tv_content.setText("内容");
        return convertView;
    }

    @Override
    public int getCount() {
        return super.getCount() + 1;
    }
}
